package com.example.websockettest.webSocket.utils;

import lombok.Data;

import javax.websocket.Session;
import java.util.List;

@Data
public class SessionAndUid {
    private int sessionId;
    private int uid;
    public static void putIfAbsent(List<SessionAndUid> save, int sessionId, int uid){
        for(SessionAndUid e:save){
            if(e.getSessionId()==sessionId){
                e.setUid(uid);
                break;
            }
        }
    }

    public SessionAndUid(int sessionId, int uid) {
        this.sessionId = sessionId;
        this.uid = uid;
    }
    public static void remove(List<SessionAndUid> save,int sessionId){
        for(SessionAndUid e:save){
            if(e.getSessionId()==sessionId){
                save.remove(e);
                return;
            }
        }
    }
    public static long getUid(List<SessionAndUid> save,int sessionId){
        for(SessionAndUid e:save){
            if(e.getSessionId()==sessionId){
                return e.getUid();
            }
        }
        return 0;
    }

    public SessionAndUid(String sessionId) {
        this.sessionId =Integer.parseInt(sessionId);
    }
}
